package net.trombonium.steroid;

import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SurveyPicker extends Activity implements OnClickListener{
	
	int[] ids;
	Button[] buttons;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TreeMap<Integer, String> surveys = (new DBHelper(this)).getSurveys();
        LinearLayout lin = new LinearLayout(this);
        lin.setOrientation(LinearLayout.VERTICAL);
        buttons = new  Button[surveys.size()];
        ids = new int[surveys.size()];
        Iterator it = surveys.entrySet().iterator();
        int index=0;
        while (it.hasNext()) {
            Map.Entry survey = (Map.Entry)it.next();
            buttons[index] = new Button(this);
            ids[index] = ((Integer)survey.getKey()).intValue();
            buttons[index].setText((String)survey.getValue());
            buttons[index].setId(((Integer)survey.getKey()).intValue());
            buttons[index].setOnClickListener(this);
            lin.addView(buttons[index]);
            ++index;
            //System.out.println(pairs.getKey() + " = " + pairs.getValue());
        }
        this.setContentView(lin);
    }

	public void onClick(View v) {
		int sId = v.getId();
		Intent surveyorIntent = new Intent(this, Surveyor.class);
		surveyorIntent.putExtra(Steroid.S_ID, sId);
		startActivity(surveyorIntent);
		finish();
	}
    
}
